﻿namespace _3Ex1TimeCalculator
{
    public class TimeCalculator
    {
        /// <summary>
        /// Calculate time taken from a given start time to a given end time.
        /// </summary>
        /// <param name="startHourValue"></param>
        /// <param name="startMinuteValue"></param>
        /// <param name="endHourValue"></param>
        /// <param name="endMinuteValue"></param>
        /// <returns></returns>
        public int Calculate(string startHourValue, string startMinuteValue, string endHourValue, string endMinuteValue)
        {
            int totalStartMinutes = Parse(startMinuteValue) + (Parse(startHourValue) * 60);
            int totalEndMinutes = Parse(endMinuteValue) + (Parse(endHourValue) * 60);

            int totalMinutes;
            if (totalEndMinutes >= totalStartMinutes)
            {
                totalMinutes = totalEndMinutes - totalStartMinutes;
            }
            else
            {
                totalMinutes = totalEndMinutes + ((24 * 60) - totalStartMinutes);
            }

            return totalMinutes;
        }

        private static int Parse(string endHour)
        {
            return int.Parse(endHour);
        }
    }
}
